" When started as "evim", evim.vim will already have done these settings, bail out.
if v:progname =~? "evim"
  finish
endif

" Get the defaults that most users want.
source $VIMRUNTIME/defaults.vim

if has("gui_running")
  " Switch on highlighting the last used search pattern.
  set background=light
  set guifont=DejaVu_Sans_Mono:h10
  set lines=35 columns=100
  set hlsearch
  color lucius
else
  set background=dark
  color vividchalk
endif

" Put these in an autocmd group, so that we can delete them easily.
augroup vimrcEx
  au!
  " For all text files set 'textwidth' to 86 characters.
  autocmd FileType text setlocal textwidth=86
  autocmd FileType python setlocal et sta sw=4 sts=4
augroup END

" Add optional packages.
"
" The matchit plugin makes the % command work better, but it is not backwards
" compatible.
" The ! means the package won't be loaded right away but when plugins are
" loaded during initialization.
if has('syntax') && has('eval')
  packadd! matchit
endif

" The following are commented out as they cause vim to behave a lot
" differently from regular Vi. They are highly recommended though.
set showmatch           " Show matching brackets.
set ignorecase          " Do case insensitive matching
set smartcase           " Do smart case matching
set incsearch           " Incremental search
set autowrite           " Automatically save before commands like :next and :make
set hidden              " Hide buffers when they are abandoned
set autoindent          " always set autoindenting on
set noswapfile          " do NOT use a swapfile
set nobackup            " do NOT keep a backup file, use versions instead
set nowrap              " do NOT wraplines longer than the width of the window
set autowrite           " automatically save before cammands like next and make
set autoread            " automatically read changed files again
set mousehide           " hide the mouse when typing text
set cmdheight=2         " make command line twolines high
set complete+=k         " scan the files given with the 'dictionary' option
set laststatus=2        " always show status line
set wildignore=*.bak,*.o,*.e,*~,*.dat,*.class,*.a,*.obj
set statusline=%f%m%r%w%=[%{&ff}][%{&fenc}]%y[%l,%v][%P]

set expandtab
set tabstop=8
set shiftwidth=4
set encoding=utf-8
set fileencoding=utf-8
set fileencodings=ucs-bom,utf-8,cp936,cp1252,default,latin1

" Edit another file in the same directory as the current file
" uses expression to extract path from current file's path
map ,e :e <C-R>=expand("%:p:h") . "\\" <CR>
map ,r :r <C-R>=expand("%:p:h") . "\\" <CR>
map  <buffer>  <silent>  <F11>    <ESC>:Tlist<CR>
imap <buffer>  <silent>  <F11>    <ESC>:Tlist<CR>
map  <buffer>  <silent>  <C-F11>  <ESC>:TlistUpdate<CR>
imap <buffer>  <silent>  <C-F11>  <ESC>:TlistUpdate<CR>

"-------------------------------------------------------------------------------
"    F2   -  write file without confirmation
"    F3   -  call file explorer Ex
"    F4   -  show tag under curser in the preview window (tagfile must exist!)
"    F5   -  open quickfix error window
"    F6   -  close quickfix error window
"    F7   -  display previous error
"    F8   -  display next error
"-------------------------------------------------------------------------------
map   <silent> <F2>        :write<CR>
map   <silent> <F3>        :Explore<CR>
nmap  <silent> <F4>        :exe ":ptag ".expand("<cword>")<CR>
map   <silent> <F5>        :copen<CR>
map   <silent> <F6>        :cclose<CR>
map   <silent> <F7>        :cp<CR>
map   <silent> <F8>        :cn<CR>
"
imap  <silent> <F2>   <Esc>:write<CR>
imap  <silent> <F3>   <Esc>:Explore<CR>
imap  <silent> <F4>   <Esc>:exe ":ptag ".expand("<cword>")<CR>
imap  <silent> <F5>   <Esc>:copen<CR>
imap  <silent> <F6>   <Esc>:cclose<CR>
imap  <silent> <F7>   <Esc>:cp<CR>
imap  <silent> <F8>   <Esc>:cn<CR>
"
"-------------------------------------------------------------------------------
" Fast switching between buffers
" The current buffer will be saved before switching to the next one.
" Choose :bprevious or :bnext
"-------------------------------------------------------------------------------
 map  <silent> <C-tab>  <Esc>:if &modifiable && !&readonly &&
     \                  &modified <CR> :write<CR> :endif<CR>:bnext<CR>
imap  <silent> <C-tab>  <Esc>:if &modifiable && !&readonly &&
     \                  &modified <CR> :write<CR> :endif<CR>:bnext<CR>
"
"-------------------------------------------------------------------------------
" Leave the editor with Ctrl-q : Write all changed buffers and exit Vim
"-------------------------------------------------------------------------------
nmap  <C-q>    :wqa<CR>
